<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加账号</title>
    <style>
        .wu-m5>input{
            margin-bottom: 5px;
        }
    </style>
</head>
<body>
<div>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 自动洗车
        <span class="c-gray en">&gt;</span>
        账户管理
        <span class="c-gray en">&gt;</span>
        添加账号
    </nav>
    <div class="page-container">
        <form action="" method="post" class="form form-horizontal" id="form-accountMs-add">
            <input type="text" class="form-control" value="1" placeholder="" id="autoAccountMsAdd-sysUserId" name="sysUserId" style="display: none">
            <input type="text" class="form-control" value="0" placeholder="" id="autoAccountMsAdd-bizType" name="bizType" style="display: none">
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>用户姓名：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="autoAccountMsAdd-bizName" name="bizName">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>联系电话：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="" id="autoAccountMsAdd-phone" name="phone">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>账号：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" placeholder="必填项" name="userName" id="autoAccountMsAdd-userName" value="">
                </div>
                <span id="autoMsusernameSpan"></span>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>密码：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="password" class="form-control" placeholder="必填项" name="password" id="autoAccountMsAdd-password">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>角色：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" placeholder="" name="roleId" id="autoAccountMsAdd-roleId">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">备注：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <textarea id="autoAccountMsAdd-bizDesc" name="bizDesc" cols="90" rows="5" class="textarea valid" placeholder="请输入备注..."></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>状态：</label>
                <div class="formControls col-xs-4 col-sm-4 skin-minimal">
                    <div class="radio-box">
                        <input type="radio" id="autoAccountMsAdd-state-1" name="bizState" value="0" checked>
                        <label for="autoAccountMsAdd-state-1">开启</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="autoAccountMsAdd-state-2" name="bizState" value="1">
                        <label for="autoAccountMsAdd-state-2">禁用</label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input id="autoAccountMsAdd-merchantAddBut" onclick="merchantautoAccountMsAddFun.submitAction();return false;" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"/>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    //商户管理，添加服务
    var merchantautoAccountMsAddFun;

    merchantautoAccountMsAddFun = {
        init: function () {
            let _this = this;
            _this.bootstrapvalidatorForm();

            //加载角色
            $.ajax({
                type: "GET",
                url: "biz/getSelectAutoWashRole",
                dataType: "json",
                success: function (data) {
                    $("#autoAccountMsAdd-roleId").select2({
                        data: data,
                        placeholder: '请选择'
                    });
                },
                error: function () {
                    alert("error");
                }
            });

        },
        //表单提交
        submitAction: function () {
            //bootstrap验证
            var bootstrapValidator = $("#form-accountMs-add").data('bootstrapValidator');
            bootstrapValidator.validate();
            if(bootstrapValidator.isValid()){
                /*验证通过且roleId不为空*/
                $("#form-accountMs-add").submit();
            } else {
                /*验证通过，不判断是否为空*/
                return;
            }

            //提交
            $.ajax({
                type: "POST",
                url: "biz/addBizTenant",
                data: $("#form-accountMs-add").serialize(),
                dataType: "json",
                success: function (data) {
                    if (data.state) {
                        layer.msg('添加账号成功', {icon: 1});

                        //关闭新增窗口
                        removeIframe();
                        merchantAutowashAccountMsFun.searchAction();
                    } else {
                        $("#autoMsusernameSpan").text(data.message);
                    }
                },
                error: function () {
                    alert("error");
                }
            });
        },
        //bootstrap验证
        bootstrapvalidatorForm: function () {
            $('#form-accountMs-add').bootstrapValidator({
                message: 'This value is not valid',
                excluded : [':disabled'],
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    bizName: {
                        validators: {
                            notEmpty: {
                                message: '用户姓名不能为空'
                            }
                        }
                    },
                    phone: {
                        validators: {
                            regexp: {
                                regexp: /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/,
                                message: '联系电话格式不正确'
                            }
                        }
                    },
                    userName: {
                        validators: {
                            notEmpty: {
                                message: '账号不能为空'
                            },
                            stringLength: {
                                min: 4,
                                max: 50,
                                message: '账号长度必须在4到50位之间'
                            },
                            threshold:4,
                            remote:{
                                url:"biz/checkTenantName",
                                message: "该账号已存在",
                                delay: 2000,
                                type:"GET"
                            }
                        }
                    },
                    password: {
                        validators: {
                            notEmpty: {
                                message: '密码不能为空'
                            },
                            stringLength: {
                                min: 6,
                                max: 32,
                                message: '密码长度必须在6到32位之间'
                            }
                        }
                    },
                }
            });
        }
    };

    merchantautoAccountMsAddFun.init();

</script>
</body>
</html>